<div class="layui-fluid layui-anim website-anim" id="website-expert" lay-title="专家管理">
    <div class="layui-row website-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body website-table-full">
                    <form class="layui-form layui-table-form" lay-filter="expert-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-input-inline">
                                            <input type="text" name="name" autocomplete="off" class="layui-input" placeholder="请输入专家姓名">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">学科分类</label>
                                        <div class="layui-input-inline">
                                            <select name="subjectTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${subjectTypes}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">京内/京外</label>
                                        <div class="layui-input-inline">
                                            <select name="districtTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${districts}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">理论/实务</label>
                                        <div class="layui-input-inline">
                                            <select name="featureTypeCode">
                                                <option value="">请选择</option>
                                                <option
                                                        th:each="item : ${features}"
                                                        th:value="${item.code}" th:text="${item.name}">
                                                </option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary website-button-blue-plain table-action"
                                     id="query">
                                    查询
                                </div>
                            </div>
                        </div>
                    </form>

                    <input type="hidden" id="expertGroupId" autocomplete="off" class="layui-input"
                           data-th-value="${expertGroupId}"/>
                    <table lay-filter="chooseExpertTable" lay-data="{id: 'chooseExpertTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="expert-class">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-district">
    {{#
    var dict=layui.dict.getByCode(d.districtTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-feature">
    {{#
    var dict=layui.dict.getByCode(d.featureTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-position">
    {{#
    var dict=layui.dict.getByCode(d.positionTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-title">
    {{#
    var dict=layui.dict.getByCode(d.titleTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>

<script type="text/html" id="expert-choose">
    <a lay-event="chooseExpert" class="website-green">选择</a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'website','upload','dict'], function () {
        var $ = layui.jquery,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            dict = layui.dict,
            $view = $('#website-expert'),
            $query = $view.find('#query'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            upload = layui.upload,
            tableIns;

        form.render();
        initTable();
        table.on('tool(chooseExpertTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'chooseExpert') {
                website.ajaxPost(ctx + 'reviews/expertGroup/'+ $("#expertGroupId").val() + '/commit/' + data.expertId, null, function () {
                    layer.closeAll();
                    website.alert.success('操作成功');
                    window.location.reload();
                });
                return false;
            }
        });
        table.on('sort(chooseExpertTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });
        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });
        function initTable() {
            tableIns = website.table.init({
                elem: $view.find('table'),
                id: 'chooseExpertTable',
                url: ctx + 'expert/list',
                cols: [[
                   /* {type: 'checkbox'},*/
                    { type: 'numbers', title: '序号'},
                    {field: 'name', title: '专家姓名', minWidth: 100},
                    {title: '学科分类', templet: '#expert-class'},
                    {title: '京内/京外', templet: '#expert-district'},
                    {title: '理论/实务', templet: '#expert-feature'},
                    {field: 'company', title: '所在单位'},
                    // {title: '行政职位', templet: '#expert-position'},
                    {field: 'titleTypeCode',title: '职称', minWidth: 100},
                    {field: 'phone', title: '联系电话', minWidth: 100},
                    {field: 'address', title: '通讯地址', minWidth: 150},
                    {title: '操作', toolbar: '#expert-choose', minWidth: 200}
                ]]
            });
        }
        function getQueryParams() {
            var params = $searchForm.serializeJson();
            params.invalidate_ie_cache = new Date();
            return params;
        }
    })
</script>